package py.com.fms.converter;

import java.io.Serializable;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

import org.jboss.seam.Component;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.log.Log;

import py.com.fms.prd.bean.FamilyBean;
import py.com.fms.session.WithinHolder;

@SuppressWarnings("unused")
@Name("familyConverter")

public class FamilyConverter implements Converter, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1131363297101723938L;
	
	@Logger
	private Log log;

	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		// TODO Auto-generated method stub
		if (arg2 != null) {
			try {
				WithinHolder aid = (WithinHolder)Component.getInstance(WithinHolder.class, true);
				if (aid == null) {
					return null;
				}
				FamilyBean bean = aid.familyData(arg2);
				return bean;

			} catch (ConverterException e) {
				this.log.error(e);
			}
		}
		return null;
	}

	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		// TODO Auto-generated method stub
		if (arg2 instanceof FamilyBean) {
			FamilyBean bean = (FamilyBean) arg2;
			return bean.getCod();

		}
		return null;
	}

}
